/* Copyright (C) 2017-2099 All right reserved
 * For free
 *
 * @file queue.c
 * @brieif 环形消息队列初始化及其他接口头文件
 * @author qigaohua, qigaohua168@163.com
 * @version 0.1.0
 * @date 2020-08-11
 */

#ifndef _H_QUEUE_H
#define _H_QUEUE_H


#ifdef __cplusplus
extern "C" {
#endif


typedef struct _queue {
    void **data;
    unsigned int head;
    unsigned int tail;
    unsigned int cnt;
    unsigned int size; // power of 2
    unsigned int mask;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} queue_t;


queue_t * queue_create(unsigned int size);
void queue_destroy(queue_t *q);
void * dequeue(queue_t *q);
void * dequeue_nolock(queue_t *q);
int enqueue(queue_t *q, void *val);
int enqueue_nolock(queue_t *q, void *val);
int queue_is_empty(queue_t *q);
int queue_is_full(queue_t *q);
int queue_is_full_nolock(queue_t *q);
int queue_is_empty_nolock(queue_t *q);



#ifdef __cplusplus
}
#endif

#endif
